﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using td.Core;
using td.Core.DiscoverAddins;
using System.Threading;
using CG.Security.Principal;
using td.Core.Security;
using DevExpress.XtraEditors;

namespace td.Core
{
    public class SercurityDelRightCommand : td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            if (XtraMessageBox.Show("你真的要删除当前权限吗？","",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
            {
                var p = WorkBenchSingleTon.WorkBench.GetActivteTabPage();
                if (p != null)
                {
                    var r = ((RightManagerForm)(p.ViewContentControl));
                    int id = r.RightList[r.gridControl1.gridView1.FocusedRowHandle].right_id;
                    CG.Security.RightManager.Delete(id);
                    r.BindData();
                }
                
            }
    
        }
        public override bool IsEnabled
        {
            get
            {
                var smf = WorkBenchSingleTon.WorkBench.GetActivteTabPage();
                if (smf == null) return false;
                if (smf.Title != "权限管理") return false;
                CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
                CustomIdentity ci = (CustomIdentity)cp.Identity;
                return cp.IsInRole("Admin");
            }
            set
            {
                base.IsEnabled = value;
            }
        }
    }
}
